package cn.jit.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import cn.jit.po.User;

public class UserValidator implements Validator{

	@Override
	public boolean supports(Class<?> clazz) {
		return User.class.equals(clazz);
	}

	@Override
	public void validate(Object obj, Errors errors) {
		ValidationUtils.rejectIfEmpty(errors, "username", null, "用户名是必须的.");
		
		User user = (User) obj;
		
		if (null == user.getPassword() || "".equals(user.getPassword())) {
			errors.rejectValue("password", null, "密码是必须的.");
		}
			
	}
	
}
